package com.elow.testffmpeg.Demo2;

import com.elow.testffmpeg.BufferUtil;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import javax.microedition.khronos.opengles.GL10;

public class Dian {
    private IntBuffer verBuffer;
    private IntBuffer colorBuffer;
    private ByteBuffer indexBuffer;

    public Dian () {
        init();
    }

    private void init() {
        //顶点数据

        int UNIT_SIZE = 10000;//比例
        int var[] = new int[]{//初始化6个点,每三个一组(x,y,z坐标)
                -3 * UNIT_SIZE, -2 * UNIT_SIZE, 0,
                0, -2 * UNIT_SIZE, 0,
                -1 * UNIT_SIZE, 1 * UNIT_SIZE, 0,
                2 * UNIT_SIZE, -3 * UNIT_SIZE, 0,
                1 * UNIT_SIZE, 2 * UNIT_SIZE, 0,

                2 * UNIT_SIZE, 1 * UNIT_SIZE, 0
        };

        verBuffer = BufferUtil.iBuffer(var);//创建数据缓冲

        //颜色数据
        int one = 65536;//支持65536色彩通道
        //顶点个数=颜色个数
        //颜色数据(RGB A)
        int color[] = new int[]{
                one, 0, 0, 0,
                one, 0, 0, 0,
                one, 0, 0, 0,
                one, 0, 0, 0,
                one, 0, 0, 0,
                one, 0, 0, 0
        };
        colorBuffer = BufferUtil.iBuffer(color);

        //创建索引数组
        byte index[] = new byte[]{
                0, 1, 2, 3, 4, 5
        };

        indexBuffer = BufferUtil.bBuffer(index);//注意此处为byte类型
    }

    //绘制自身
    public void drawSelf(GL10 gl) {
        //启用顶点数组坐标
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        //启用顶点颜色数组
        gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

        //设置画笔,给画笔设置顶点数据
        gl.glVertexPointer(3,//verBuffer中多少个数据是一个顶点
                GL10.GL_FIXED,//数据类型-这个代表整形
                0,//顶点间隔,默认0
                verBuffer );//顶点数据

        //给画笔指定顶点颜色数据
        gl.glColorPointer(4,GL10.GL_FIXED,0,colorBuffer);//同顶点数据

        gl.glPointSize(20);//设置点大小,太小的话看不见
        gl.glDrawElements(GL10.GL_POINTS,//绘制类型
                6, //绘制顶点个数,即索引数组中点个数,可小于数组长度
                GL10.GL_UNSIGNED_BYTE, indexBuffer);
    }
}
